//
//  UILabel+SGExtension.swift
//  QingLiuSwift
//
//  Created by xyanl on 2023/9/1.
//

import UIKit

extension UILabel {
 
    func getTextHeight() -> CGFloat {
        
        let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: font as Any]
        /**
         usesLineFragmentOrigin: 整个文本将以每行组成的矩形为单位计算整个文本的尺寸
         usesFontLeading:
         usesDeviceMetrics:
         @available(iOS 6.0, *)
         truncatesLastVisibleLine:
         */
        let option = NSStringDrawingOptions.usesLineFragmentOrigin
        let rect: CGRect = text!.boundingRect(with: CGSize(width: self.bounds.width, height: CGFLOAT_MAX), options: option, attributes: attributes, context: nil)
        return rect.size.height
    }
    
    
    
}
